<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script>
    var c=0;//全局变量
    //有返回值并且有参函数
    function qiuhe(a,b){
      var sum = 0;
      for(var i=a;i<=b;i++){
        sum = sum + i;
      }
      return sum;
    }
    //无返回值并且无参
    function jisuan(){
      var ele = document.getElementsByTagName("input");
      var a = Number(ele[0].value);
      var b = Number(ele[1].value);
      ele[2].value = qiuhe(a,b);
    }
  
    //自定义函数，求n的k次方
    function cifang(n,k){
      var ji = 1;
      for(var i=1;i<=k;i++){
        ji = ji * n;
      }
      return ji;
    }
    function jisuan_cifang(){
      document.getElementsByClassName("cifang")[2].value
  = cifang(
    Number(document.getElementsByClassName("cifang")[0].value),
    Number(document.getElementsByClassName("cifang")[1].value),
  )
    }
  
    //自定义函数，判断n是不是完数
    function wanshu(n){
      var sum = 0;
      for(var i = 1;i<n;i++){
        if(n%i==0){
          sum += i;
        }
      }
      if(sum == n){
        return true;
      }else{
        return false;
      }
    }
    function allWanshu(a,b) {
      for(let i=a;i<=b;i++){
        if(wanshu(i)){
          console.log(i);
        }
      }
    }
    window.onload = allWanshu(1,1000);
    // es6:  ECMAScript6
    // var 
    // let
    // const

    //箭头函数
    function he(a,b){
      return a+b;
    }
    (a,b)=>a+b;
    (a,b)=>{return a+b;}
    function jiecheng(n){
      let ji=1;
      for(let i=1;i<=n;i++){
        ji *= i;
      }
      return ji;
    }
    (n)=>{
      let ji=1;
      for(let i=1;i<=n;i++){
        ji *= i;
      }
      return ji;
    }

    //回调函数
    function cal(num1,num2,fn){
      return fn(num1,num2);
    }
    cal(45,55,function(a,b){
      return a+b;
    })
    cal(45,55,function(a,b){
      return a*b;
    })
   
  </script>
</head>
<body>
  <input type="text" placeholder="a">到
  <input type="text" placeholder="b">之间的总和
  <input type="text" placeholder="结果">
  <input type="button" value="计算" onclick="jisuan()">
  <hr>
  <h3>次方和</h3>
  <input type="text" placeholder="n" class="cifang">^
  <input type="text" placeholder="k" class="cifang">=
  <input type="text" placeholder="结果" class="cifang">
  <input type="button" value="计算" onclick='jisuan_cifang()'>
</body>
</html>